import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hand_writing/view/index/index_provider.dart';
import 'package:provider/provider.dart';
import '../../database/database.dart';
import 'write_box_state.dart';

class WriteBoxProvider extends ChangeNotifier {
  late WriteBoxState state;
  final AppDatabase database;
  WriteBoxProvider(Note note,this.database) {
    state = WriteBoxState(note: note);
  }

  void toggleExpanded() {
    state.isExpanded = !state.isExpanded;
    notifyListeners();
  }

  delete(BuildContext context)async{
    var indexProvider = context.read<IndexProvider>();
    var result = await showDialog(
      barrierDismissible: false,
      context: context,
      builder: (ctx) {
        return AlertDialog(
          title: Text("提示信息"),
          content: Text("您确定要删除吗？"),
          actions: <Widget>[
            TextButton(
              onPressed: () {
                print('取消');
                Navigator.of(ctx).pop("Cancel");
              },
              child: Text("取消"),
            ),
            TextButton(
              onPressed: () {
                print('确定');
                Navigator.of(ctx).pop("Ok");
              },
              child: Text("确定"),
            ),
          ],
        );
      },
    );
    print('result: $result');
    if(result == "Ok"){
      await indexProvider.delete(state.id);
    }
  }

}

